from game import zz_game
from zz import zz_log, zz_img

log = zz_log.of()


class Game(zz_game.ZZ_Game):
    def __init__(self, d, has_prize=True, play_count=1):
        super().__init__(d, has_prize)
        self.play_count = play_count

    def get_name(self):
        return "暴走弹头"

    def game_alert(self):
        self.alert_close_by_file('./game/img/暴走弹头')

    def play_alert(self):
        if not self.img_exit('./game/img/暴走弹头/play_alert.png', 3):
            self.log_msg("无选择弹窗", False)
            return

        self.log_msg("存在选择弹窗，点击选择", False)
        w, h = self.d.window_size()
        self.d.click(w / 2, h / 2)

    def play_email(self):
        """
        领取邮箱奖励
        """
        self.img_click_if_exists('点击邮箱', './game/img/暴走弹头/play_email.png', './game/img/暴走弹头/play_email_1.png')
        self.log_msg(f"点击领取")
        self.img_click('./game/img/暴走弹头/play_email_1.png')
        self.click_bottom()
        self.click_bottom()

    def handle_main(self):
        self.log_msg("等待进入游戏主界面")
        self.img_exit('./game/img/暴走弹头/game_main.png', 100)
        self.log_msg("已进入游戏主界面")

        if self.not_prize_handle():
            return False

        self.game_alert()

        self.play_email()

        self.swipe_right(0.2)

        for i in range(self.play_count):
            index = i + 1
            self.log_msg(f"{index}-开始进入战斗")
            self.img_click('./game/img/暴走弹头/play.png')
            self.log_msg(f"{index}-等待进入战斗界面")
            self.img_exit('./game/img/暴走弹头/play_main.png', 100)
            self.log_msg(f"{index}-已进入战斗界面")

            self.img_click_if_exists(f"{i}-点击暂停", './game/img/暴走弹头/play_stop.png', './game/img/暴走弹头/play_exit.png')
            self.log_msg(f"{index}-点击撤退")
            self.img_click('./game/img/暴走弹头/play_exit.png')
            self.log_msg(f"{index}-战斗结束，点击确定")
            self.img_click('./game/img/暴走弹头/play_done_1.png')

        return True
